package com.example.anliku.controller;

import com.example.anliku.entity.Message;
import com.example.anliku.entity.User;
import com.example.anliku.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

@Api(tags = "用户模块")
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation(value = "用户登录")
    @PostMapping(value = "/login")
    public Message login(String userId, String userPwd){
        return userService.login(userId, userPwd);
    }

    @ApiOperation(value = "用户注册")
    @PostMapping(value = "/register")
    public Message register(User user){
        return userService.insertSelective(user);
    }

    @ApiOperation(value = "用户密码修改")
    @PostMapping(value = "/put")
    public Message put(String userId,String userPwd){
        return userService.updateUserPwdByUserId(userPwd,userId);
    }

    @ApiOperation(value = "用户删除")
    @DeleteMapping(value = "/delet")
    public Message delet(String userId){
        return userService.deleteByPrimaryKey(userId);
    }

    @ApiOperation(value = "根据用户userId查询用户信息")
    @GetMapping(value = "/get")
    public Message select(String userId){
        return userService.selectByPrimaryKey(userId);
    }

    @ApiOperation(value = "查询全部用户信息")
    @GetMapping(value = "/all")
    public Message all(){
        return userService.selectALL();
    }

    @ApiOperation(value = "修改全部用户信息")
    @GetMapping(value = "/putall")
    public Message putall(User user){
        return userService.updateByPrimaryKeySelective(user);
    }

    @ApiOperation(value = "判断手机号是否注册")
    @GetMapping(value = "/phone")
    public Message phone(String userPhone){
        return userService.selectAllByUserPhone(userPhone);
    }

    @ApiOperation(value = "小程序用户绑定openId")
    @PostMapping(value = "/bindingOpenIdByUserId")
    public Message bindingOpenIdByUserId(String userId,String openId){
        return userService.bindingOpenIdByUserId(userId,openId);
    }

    @ApiOperation(value = "小程序用户解绑openId")
    @PostMapping(value = "/cancelBindingOpenIdByUserId")
    public Message cancelBindingOpenIdByUserId(String userId){
        return userService.cancelBindingOpenIdByUserId(userId);
    }

    @ApiOperation(value = "小程序登录")
    @GetMapping("/wxLogin")
    public Message wxLogin(@RequestParam String jsCode) throws IOException {
        return userService.wxLogin(jsCode);
    }
}
